/*
 * BackgroundImagePanel.java
 *
 * Created on 26 mei 2008, 22:25
 */

package com.laamella.syntherface.synths.gui;

import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Image;
import java.net.URL;
import javax.imageio.ImageIO;

/**
 *
 * @author  danny
 */
public abstract class BackgroundImagePanel extends javax.swing.JPanel {

	private Image image;
	
	protected abstract String getBackgroundImageName();
	
    /** Creates new form BackgroundImagePanel */
    public BackgroundImagePanel() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 400, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 300, Short.MAX_VALUE)
        );
    }// </editor-fold>//GEN-END:initComponents


    // Variables declaration - do not modify//GEN-BEGIN:variables
    // End of variables declaration//GEN-END:variables
	@Override protected void paintComponent(Graphics g)
	{
		super.paintComponent(g); 
		if(image==null){
			try
			{
				URL url = this.getClass().getClassLoader().getResource(getBackgroundImageName());
				image = ImageIO.read(url);
				Dimension size=new Dimension(image.getWidth(null), image.getHeight(null));
				setPreferredSize(size);
			}
			catch(Exception e){
				e.printStackTrace();
			}
		}else{
			g.drawImage(image, 0,0,null);
		}
	}

}
